package com.newer.service.crm.impl;

import java.util.List;

import javax.jws.WebMethod;
import javax.jws.WebService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.newer.dao.crm.CustomerMapper;
import com.newer.pojo.crm.Customer;
import com.newer.pojo.crm.CustomerExample;
import com.newer.pojo.crm.CustomerExample.Criteria;

@Service("customerService")
@WebService
@Transactional
public class CustomerServiceImpl implements com.newer.service.crm.iter.CustomerService {
	@Autowired
	private CustomerMapper customerMapper;

	@WebMethod
	@Override
	public List<Customer> findAll() {
		return customerMapper.selectByExample(null);
	}

	// 查询未关联到定区的客户
	@Override
	public List<Customer> findListNotAssociation() {
		CustomerExample example = new CustomerExample();
		Criteria criteria = example.createCriteria();
		criteria.andDecidedzoneIdIsNull();
		return customerMapper.selectByExample(example);
	}

	// 查询已经关联到指定定区的客户
	@Override
	public List<Customer> findListHasAssociation(Integer decidedzoneId) {
		CustomerExample example = new CustomerExample();
		if (decidedzoneId != null && !"".equals(decidedzoneId)) {
			Criteria criteria = example.createCriteria();
			criteria.andDecidedzoneIdEqualTo(decidedzoneId);
		}
		return customerMapper.selectByExample(example);
	}

	// 定区关联客户
	@Override
	public void assigncustomerstodecidedzone(Integer decidedzoneId, List<Integer> customerIds) {
		customerMapper.assigncustomerstodecidedzone(decidedzoneId, customerIds);
	}

	// 根据手机号查询客户信息
	@Override
	public Customer findCustomerByTelephone(String telephone) {
		CustomerExample example = new CustomerExample();
		if (telephone != null && !"".equals(telephone)) {
			Criteria criteria = example.createCriteria();
			criteria.andTelephoneEqualTo(telephone);
		}
		return customerMapper.selectByExample(example).get(0);
	}

	// 根据客户的地址查询定区id
	@Override
	public String findDecidedzoneIdByAddress(String address) {
		return customerMapper.findDecidedzoneIdByAddress(address);
	}

}
